package com.victor.controller.web.partner;

import java.net.URLEncoder;
import java.util.List;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.victor.entity.activity_tuikuan.ActJifen;
import com.victor.entity.activity_tuikuan.ActManjian;
import com.victor.entity.activity_tuikuan.ActMiaosha;
import com.victor.entity.activity_tuikuan.ActTuangou;
import com.victor.entity.activity_tuikuan.TuikuanSetup;
import com.victor.entity.partner.PartnerType;
import com.victor.entity.partner.PartnerUser;
import com.victor.entity.partner.food.FoodMeal;
import com.victor.entity.partner.food.FoodMealDayUse;
import com.victor.entity.partner.food.FoodMealKeshou;
import com.victor.entity.partner.food.FoodMealPhoto;
import com.victor.entity.partner.happy.HappyTheme;
import com.victor.entity.partner.happy.HappyThemeKeshou;
import com.victor.entity.partner.happy.HappyThemePhoto;
import com.victor.entity.partner.happy.HappyThemeTime;
import com.victor.entity.partner.hotel.HotelRoom;
import com.victor.entity.partner.hotel.HotelRoomExplain;
import com.victor.entity.partner.hotel.HotelRoomKeshou;
import com.victor.entity.partner.hotel.HotelRoomLabel;
import com.victor.entity.partner.hotel.HotelRoomPhoto;
import com.victor.service.PartnerService;
import com.victor.utils.Msg;

/**
 * 服务伙伴
 * 
 * @author zhangbin
 *
 */
@RestController
@RequestMapping("/partner")
public class PartnerController {
	@Autowired
	private PartnerService partnerService;

	// 获取商户类别
	@RequestMapping("/getPartnerType")
	public Msg getPartnerType(String t_type) {// t_type 商家类型（1、宾馆。2、美食。3、娱乐。）
		List<PartnerType> partnerTypes = partnerService.getPartnerType(t_type);
		return Msg.success().add("partnerTypes", partnerTypes);
	}

	/* 获取合作伙伴商家 */
	// type用户类型(1.酒店.2.美食. 3娱乐)
	// name;商户名
	// brand;// 商家品牌
	// account账号
	// t_id商户类别id
	// business_state; // 营业状态（0营业中 1歇业中 2闭店）
	@RequestMapping("/getPartnerUsers")
	public Msg getPartnerUsers(String type, String name, String brand, String account, String t_id, String business_state) {
		List<PartnerUser> partnerUsers = partnerService.getPartnerUsers(type, name, brand, account, t_id, business_state);
		return Msg.success().add("partnerUsers", partnerUsers);
	}

	// 获取商家详情
	@RequestMapping("/getPartnerUserXQ")
	public Msg getPartnerUserXQ(String partnerUserid) {
		PartnerUser partnerUser = partnerService.getPartnerUserXQ(partnerUserid);
		if (partnerUser != null) {
			return Msg.success().add("partnerUser", partnerUser);
		}
		return Msg.fail("未查询到该ID对应商家");
	}

	// 批量删除
	@RequestMapping("/batchDeletePartnerUser")
	public Msg batchDeletePartnerUser(int[] puids) {
		if (puids == null || puids.length == 0) {
			return Msg.fail("入参失败");
		}
		boolean delResult = partnerService.batchDeletePartnerUser(puids);
		return Msg.judge(delResult);
	}

	// 批量导出
	@RequestMapping("/batchExportPartnerUser")
	public void batchExportPartnerUser(String type, String name, String brand, String account, String t_id, String business_state, HttpServletResponse response, HttpServletRequest request) throws Exception {
		List<PartnerUser> partnerUsers = partnerService.getPartnerUsers(type, name, brand, account, t_id, business_state);

		// 创建poi导出数据对象
		SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
		// 创建sheet页
		Sheet sheet = sxssfWorkbook.createSheet("服务伙伴列表");

		CellRangeAddress region1 = new CellRangeAddress(0, 1, (short) 0, (short) 6);
		// 参数1：起始行 参数2：终止行 参数3：起始列 参数4：终止列
		sheet.addMergedRegion(region1);
		Row headTitle = sheet.createRow(0);
		headTitle.createCell(0).setCellValue("服务伙伴列表");

		// 创建表头
		Row headRow = sheet.createRow(4);
		// 设置表头信息
		headRow.createCell(0).setCellValue("商家主键id");
		headRow.createCell(1).setCellValue("账号");
		headRow.createCell(2).setCellValue("密码");
		headRow.createCell(3).setCellValue("商户类别表id");
		headRow.createCell(4).setCellValue("用户类型(1.酒店.2.美食. 3娱乐)");
		headRow.createCell(5).setCellValue("商家名称");
		headRow.createCell(6).setCellValue("商家品牌");
		headRow.createCell(7).setCellValue("商家介绍");
		headRow.createCell(8).setCellValue("商家电话");
		headRow.createCell(9).setCellValue("是否为首页推荐 0否 1是");
		headRow.createCell(10).setCellValue("位置--全");
		headRow.createCell(11).setCellValue("位置备注");
		headRow.createCell(12).setCellValue("位置经度");
		headRow.createCell(13).setCellValue("位置纬度");
		headRow.createCell(14).setCellValue("创建人id");
		headRow.createCell(15).setCellValue("是否冻结标志 0.正常 1.冻结");
		headRow.createCell(16).setCellValue("封面图");
		headRow.createCell(17).setCellValue("360全景图");
		headRow.createCell(18).setCellValue("视频");
		headRow.createCell(19).setCellValue("营业时间");
		headRow.createCell(20).setCellValue("营业状态（0营业中 1歇业中 2闭店）");
		headRow.createCell(21).setCellValue("主题类别");
		headRow.createCell(22).setCellValue("星级");
		headRow.createCell(23).setCellValue("价格");
		headRow.createCell(24).setCellValue("名称");
		headRow.createCell(25).setCellValue("主题");

		// 遍历上面数据库查到的数据
		for (PartnerUser partnerUser : partnerUsers) {
			Row dataRow = sheet.createRow(sheet.getLastRowNum() + 1);
			dataRow.createCell(0).setCellValue(partnerUser.getP_id());
			dataRow.createCell(1).setCellValue(partnerUser.getAccount());
			dataRow.createCell(2).setCellValue(partnerUser.getPassword());
			dataRow.createCell(3).setCellValue(partnerUser.getT_id());
			dataRow.createCell(4).setCellValue(partnerUser.getType());
			dataRow.createCell(5).setCellValue(partnerUser.getName());
			dataRow.createCell(6).setCellValue(partnerUser.getBrand());
			dataRow.createCell(7).setCellValue(partnerUser.getIntroduce());
			dataRow.createCell(8).setCellValue(partnerUser.getTelphone());
			dataRow.createCell(9).setCellValue(partnerUser.getIfhomepage());
			dataRow.createCell(10).setCellValue(partnerUser.getPosition());
			dataRow.createCell(11).setCellValue(partnerUser.getPosition_remarks());
			dataRow.createCell(12).setCellValue(partnerUser.getPosition_lon());
			dataRow.createCell(13).setCellValue(partnerUser.getPosition_lat());
			dataRow.createCell(14).setCellValue(partnerUser.getAdminid());
			dataRow.createCell(15).setCellValue(partnerUser.getFrozen());
			dataRow.createCell(16).setCellValue(partnerUser.getCover_photo());
			dataRow.createCell(17).setCellValue(partnerUser.getView360_photo());
			dataRow.createCell(18).setCellValue(partnerUser.getVideo());
			dataRow.createCell(19).setCellValue(partnerUser.getBusiness_time());
			dataRow.createCell(20).setCellValue(partnerUser.getBusiness_state());
			dataRow.createCell(21).setCellValue(partnerUser.getF_theme());
			dataRow.createCell(22).setCellValue(partnerUser.getH_star());
			dataRow.createCell(23).setCellValue(partnerUser.getH_price());
			dataRow.createCell(24).setCellValue(partnerUser.getY_name());
			dataRow.createCell(25).setCellValue(partnerUser.getY_theme());

		}
		// 下载导出文件名
		String filename = "服务伙伴列表";
		// 设置头信息
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/vnd.ms-excel");
		// 一定要设置成xlsx格式
		response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xlsx", "UTF-8"));
		// 创建一个输出流
		ServletOutputStream outputStream = response.getOutputStream();
		// 写入数据
		sxssfWorkbook.write(outputStream);
		// 关闭
		outputStream.close();
		sxssfWorkbook.close();

	}

	// 批量冻结
	@RequestMapping("/batchFrozenPartnerUser")
	public Msg batchFrozenPartnerUser(int[] puids) {
		if (puids == null || puids.length == 0) {
			return Msg.fail("入参失败");
		}
		boolean updResult = partnerService.batchFrozenPartnerUser(puids);
		return Msg.judge(updResult);
	}

	// 添加房间
	@RequestMapping("/addHotelRoom")
	public Msg addHotelRoom(@RequestBody HotelRoom hotelRoom) {
		// 将房间信息添加入数据库并返回酒店房间id
		int i = partnerService.addHotelRoom(hotelRoom);
		if (i > 0) {
			if (hotelRoom.getHotelRoomLabels() != null && hotelRoom.getHotelRoomLabels().size() > 0) {
				for (HotelRoomLabel hotelRoomLabel : hotelRoom.getHotelRoomLabels()) {
					// 将房间id放入标签中
					hotelRoomLabel.setR_id(String.valueOf(hotelRoom.getR_id()));
					// 添加标签数据
					partnerService.addHotelRoomLabel(hotelRoomLabel);
				}
			}
			if (hotelRoom.getHotelRoomExplains() != null && hotelRoom.getHotelRoomExplains().size() > 0) {
				for (HotelRoomExplain hotelRoomExplain : hotelRoom.getHotelRoomExplains()) {
					// 将房间id放入预定说明
					hotelRoomExplain.setR_id(String.valueOf(hotelRoom.getR_id()));
					// 添加预定说明
					partnerService.addHotelRoomExplain(hotelRoomExplain);
				}
			}
			if (hotelRoom.getHotelRoomPhotos() != null && hotelRoom.getHotelRoomPhotos().size() > 0) {
				for (HotelRoomPhoto hotelRoomPhoto : hotelRoom.getHotelRoomPhotos()) {
					// 将房间id放入房间介绍图片
					hotelRoomPhoto.setR_id(String.valueOf(hotelRoom.getR_id()));
					// 添加房间介绍图片
					partnerService.addHotelRoomPhoto(hotelRoomPhoto);
				}
			}
			// 退款设置信息
			if (hotelRoom.getIf_tuikuan().equals("2") || hotelRoom.getIf_tuikuan().equals("3")) {// 如果退款状态是2或者3
				TuikuanSetup tuikuanSetup = hotelRoom.getTuikuanSetup();
				tuikuanSetup.setTable_id(String.valueOf(hotelRoom.getR_id()));
				tuikuanSetup.setTable_name("hotel_room");
				partnerService.addTuikuanSetup(tuikuanSetup);
			}

			// 活动
			if (hotelRoom.getIf_join_activity().equals("1")) {// 如果参加活动状态为1---参加活动
				if (hotelRoom.getJoin_activity_type().equals("1")) {// 团购活动one
					ActTuangou actTuangou = hotelRoom.getActTuangou();// 团购
					actTuangou.setTable_id(String.valueOf(hotelRoom.getR_id()));
					actTuangou.setTable_name("hotel_room");
					partnerService.addActTuangou(actTuangou);
				}
				if (hotelRoom.getJoin_activity_type().equals("2")) {// 秒杀活动list
					List<ActMiaosha> actMiaoshas = hotelRoom.getActMiaoshas();// 秒杀活动
					for (ActMiaosha actMiaosha : actMiaoshas) {
						actMiaosha.setTable_name("hotel_room");
						actMiaosha.setTable_id(String.valueOf(hotelRoom.getR_id()));
						partnerService.addActMiaosha(actMiaosha);
					}
				}
				if (hotelRoom.getJoin_activity_type().equals("3")) {// 满减活动list
					List<ActManjian> actManjians = hotelRoom.getActManjians();// 满减活动
					for (ActManjian actManjian : actManjians) {
						actManjian.setTable_name("hotel_room");
						actManjian.setTable_id(String.valueOf(hotelRoom.getR_id()));
						partnerService.addActManjian(actManjian);
					}
				}
				if (hotelRoom.getJoin_activity_type().equals("4")) {// 积分兑换活动one
					ActJifen actJifen = hotelRoom.getActJifen();// 积分
					actJifen.setTable_name("hotel_room");
					actJifen.setTable_id(String.valueOf(hotelRoom.getR_id()));
					partnerService.addActJifen(actJifen);
				}
			}
			return Msg.success();
		}

		return Msg.fail("插入宾馆房间信息失败");
	}

	// 添加美食套餐
	@RequestMapping("/addFoodMeal")
	public Msg addFoodMeal(@RequestBody FoodMeal foodMeal) {
		// 将美食套餐添加入数据库并返回id
		int i = partnerService.addFoodMeal(foodMeal);
		if (i > 0) {
			if (foodMeal.getFoodMealDayUses() != null && foodMeal.getFoodMealDayUses().size() > 0) {
				for (FoodMealDayUse foodMealDayUse : foodMeal.getFoodMealDayUses()) {
					// 将房间id放入标签中
					foodMealDayUse.setFm_id(String.valueOf(foodMeal.getM_id()));
					// 添加每日可售数量
					partnerService.addFoodMealDayUse(foodMealDayUse);
				}
			}
			if (foodMeal.getFoodMealPhotos() != null && foodMeal.getFoodMealPhotos().size() > 0) {
				for (FoodMealPhoto foodMealPhoto : foodMeal.getFoodMealPhotos()) {
					// 将房间id放入预定说明
					foodMealPhoto.setM_id(String.valueOf(foodMeal.getM_id()));
					// 添加图片
					partnerService.addFoodMealPhoto(foodMealPhoto);
				}
			}
			// 退款设置信息
			if (foodMeal.getIf_tuikuan().equals("2") || foodMeal.getIf_tuikuan().equals("3")) {// 如果退款状态是2或者3
				TuikuanSetup tuikuanSetup = foodMeal.getTuikuanSetup();
				tuikuanSetup.setTable_id(String.valueOf(foodMeal.getM_id()));
				tuikuanSetup.setTable_name("food_meal");
				partnerService.addTuikuanSetup(tuikuanSetup);
			}

			// 活动
			if (foodMeal.getIf_join_activity().equals("1")) {// 如果参加活动状态为1---参加活动
				if (foodMeal.getJoin_activity_type().equals("1")) {// 团购活动one
					ActTuangou actTuangou = foodMeal.getActTuangou();// 团购
					actTuangou.setTable_id(String.valueOf(foodMeal.getM_id()));
					actTuangou.setTable_name("food_meal");
					partnerService.addActTuangou(actTuangou);
				}
				if (foodMeal.getJoin_activity_type().equals("2")) {// 秒杀活动list
					List<ActMiaosha> actMiaoshas = foodMeal.getActMiaoshas();// 秒杀活动
					for (ActMiaosha actMiaosha : actMiaoshas) {
						actMiaosha.setTable_name("food_meal");
						actMiaosha.setTable_id(String.valueOf(foodMeal.getM_id()));
						partnerService.addActMiaosha(actMiaosha);
					}
				}
				if (foodMeal.getJoin_activity_type().equals("3")) {// 满减活动list
					List<ActManjian> actManjians = foodMeal.getActManjians();// 满减活动
					for (ActManjian actManjian : actManjians) {
						actManjian.setTable_name("food_meal");
						actManjian.setTable_id(String.valueOf(foodMeal.getM_id()));
						partnerService.addActManjian(actManjian);
					}
				}
				if (foodMeal.getJoin_activity_type().equals("4")) {// 积分兑换活动one
					ActJifen actJifen = foodMeal.getActJifen();// 积分
					actJifen.setTable_name("food_meal");
					actJifen.setTable_id(String.valueOf(foodMeal.getM_id()));
					partnerService.addActJifen(actJifen);
				}
			}
			return Msg.success();
		}

		return Msg.fail("插入美食套餐信息失败");
	}

	// 添加娱乐项目
	@RequestMapping("/addHappyTheme")
	public Msg addHappyTheme(@RequestBody HappyTheme happyTheme) {
		// 将娱乐项目添加入数据库并返回id
		int i = partnerService.addHappyTheme(happyTheme);
		if (i > 0) {
			if (happyTheme.getHappyThemePhotos() != null && happyTheme.getHappyThemePhotos().size() > 0) {
				for (HappyThemePhoto happyThemePhoto : happyTheme.getHappyThemePhotos()) {
					// 将项目id放入图片
					happyThemePhoto.setT_id(String.valueOf(happyTheme.getT_id()));
					// 添加娱乐项目图片
					partnerService.addHappyThemePhoto(happyThemePhoto);
				}
			}
			if (happyTheme.getHappyThemeTimes() != null && happyTheme.getHappyThemeTimes().size() > 0) {
				for (HappyThemeTime happyThemeTime : happyTheme.getHappyThemeTimes()) {
					// 将项目id放入时间表
					happyThemeTime.setT_id(String.valueOf(happyTheme.getT_id()));
					// 添加时间
					partnerService.addHappyThemeTime(happyThemeTime);
				}
			}
			// 退款设置信息
			if (happyTheme.getIf_tuikuan().equals("2") || happyTheme.getIf_tuikuan().equals("3")) {// 如果退款状态是2或者3
				TuikuanSetup tuikuanSetup = happyTheme.getTuikuanSetup();
				tuikuanSetup.setTable_id(String.valueOf(happyTheme.getT_id()));
				tuikuanSetup.setTable_name("happy_theme");
				partnerService.addTuikuanSetup(tuikuanSetup);
			}

			// 活动
			if (happyTheme.getIf_join_activity().equals("1")) {// 如果参加活动状态为1---参加活动
				if (happyTheme.getJoin_activity_type().equals("1")) {// 团购活动one
					ActTuangou actTuangou = happyTheme.getActTuangou();// 团购
					actTuangou.setTable_id(String.valueOf(happyTheme.getT_id()));
					actTuangou.setTable_name("happy_theme");
					partnerService.addActTuangou(actTuangou);
				}
				if (happyTheme.getJoin_activity_type().equals("2")) {// 秒杀活动list
					List<ActMiaosha> actMiaoshas = happyTheme.getActMiaoshas();// 秒杀活动
					for (ActMiaosha actMiaosha : actMiaoshas) {
						actMiaosha.setTable_name("happy_theme");
						actMiaosha.setTable_id(String.valueOf(happyTheme.getT_id()));
						partnerService.addActMiaosha(actMiaosha);
					}
				}
				if (happyTheme.getJoin_activity_type().equals("3")) {// 满减活动list
					List<ActManjian> actManjians = happyTheme.getActManjians();// 满减活动
					for (ActManjian actManjian : actManjians) {
						actManjian.setTable_name("happy_theme");
						actManjian.setTable_id(String.valueOf(happyTheme.getT_id()));
						partnerService.addActManjian(actManjian);
					}
				}
				if (happyTheme.getJoin_activity_type().equals("4")) {// 积分兑换活动one
					ActJifen actJifen = happyTheme.getActJifen();// 积分
					actJifen.setTable_name("happy_theme");
					actJifen.setTable_id(String.valueOf(happyTheme.getT_id()));
					partnerService.addActJifen(actJifen);
				}
			}
			return Msg.success();
		}
		return Msg.fail("插入娱乐项目信息失败");
	}

	/** 宾馆 */
	// 上下架房间-- upordowntype --0 上架 1下架
	@RequestMapping("/upOrDownHotelRoom")
	public Msg upOrDownHotelRoom(int hotelRoomid, String upordowntype) {
		boolean updResult = partnerService.UpOrDownHotelRoom(hotelRoomid, upordowntype);
		return Msg.judge(updResult);
	}

	// 筛选（根据上下架筛选）--p_id商家id upordowntype --0 上架 1下架
	@RequestMapping("/shaixuanUporDownHotelRoom")
	public Msg shaixuanUporDownHotelRoom(String p_id, String upordowntype) {
		List<HotelRoom> hotelRooms = partnerService.shaixuanUporDown(p_id, upordowntype);
		return Msg.success().add("hotelRooms", hotelRooms);
	}

	// 获取房间详情---传房间id
	@RequestMapping("/getHotelRoomXQ")
	public Msg getHotelRoomXQ(String r_id) {
		HotelRoom hotelRoom = partnerService.getHotelRoomXQ(r_id);
		if (hotelRoom != null) {
			return Msg.success().add("hotelRoom", hotelRoom);
		}
		return Msg.fail();
	}

	// 设置可销售数量
	@RequestMapping("/setupKeshou")
	public Msg setupKeshou(@RequestBody List<HotelRoomKeshou> hotelRoomKeshous) {
		if (hotelRoomKeshous != null && hotelRoomKeshous.size() > 0) {
			for (HotelRoomKeshou hotelRoomKeshou : hotelRoomKeshous) {
				// 查询当日是否已经设置可售
				HotelRoomKeshou hotelRoomKeshou_today = partnerService.getTodayIsSetup(hotelRoomKeshou.getDate(), hotelRoomKeshou.getR_id());
				if (hotelRoomKeshou_today != null) {// 如果当日已经设置
					// 删除当日设置
					partnerService.deleteTodayHotelRoomKeshous(hotelRoomKeshou_today.getK_id());
				}
				// 添加新的设置
				partnerService.addHotelRoomKeshous(hotelRoomKeshou);
			}
		}

		return Msg.success();
	}

	// 删除房间信息
	@RequestMapping("/delHotelRoom")
	public Msg delHotelRoom(Integer r_id) {
		boolean delResult = partnerService.delHotelRoom(r_id);
		return Msg.judge(delResult);
	}

	// 修改房间信息
	@RequestMapping("/updHotelRoom")
	public Msg updHotelRoom(HotelRoom hotelRoom) {
		boolean updResult = partnerService.updHotelRoom(hotelRoom);
		return Msg.judge(updResult);
	}

	// 添加图片
	@RequestMapping("/addHotelRoomPhoto")
	public Msg addHotelRoomPhoto(HotelRoomPhoto hotelRoomPhoto) {
		int insResult = partnerService.addHotelRoomPhoto(hotelRoomPhoto);
		if (insResult > 0) {
			return Msg.success();
		}
		return Msg.fail();
	}

	// 删除宾馆图片
	@RequestMapping("/delHotelRoomPhoto")
	public Msg delHotelRoomPhoto(String photo_id) {
		boolean delResult = partnerService.delHotelRoomPhoto(photo_id);
		return Msg.judge(delResult);
	}

	/** 美食 */
	// 上下架美食商品 upordowntype 0 上架 1下架
	@RequestMapping("/upOrDownFoodMeal")
	public Msg upOrDownFoodMeal(int foodMealid, String upordowntype) {
		boolean updResult = partnerService.upOrDownFoodMeal(foodMealid, upordowntype);
		return Msg.judge(updResult);
	}

	// 筛选（根据上下架筛选）--p_id商家id upordowntype --0 上架 1下架
	@RequestMapping("/shaixuanUporDownFoodMeal")
	public Msg shaixuanUporDownFoodMeal(String p_id, String upordowntype) {
		List<FoodMeal> foodMeals = partnerService.shaixuanUporDownFoodMeal(p_id, upordowntype);
		return Msg.success().add("foodMeals", foodMeals);
	}

	// 获取美食详情
	@RequestMapping("/getFoodMealXQ")
	public Msg getFoodMealXQ(String m_id) {
		FoodMeal foodMeal = partnerService.getFoodMealXQ(m_id);
		if (foodMeal != null) {
			return Msg.success().add("foodMeal", foodMeal);
		}
		return Msg.fail();
	}

	// 美食设置可销售数量
	@RequestMapping("/setupKeshouFoodMeal")
	public Msg setupKeshouFoodMeal(@RequestBody List<FoodMealKeshou> foodMealKeshous) {
		if (foodMealKeshous != null && foodMealKeshous.size() > 0) {
			for (FoodMealKeshou foodMealKeshou : foodMealKeshous) {
				// 美食查询当日是否已经设置可售
				FoodMealKeshou foodMealKeshou_today = partnerService.getTodayIsSetupFoodMeal(foodMealKeshou.getDate(), foodMealKeshou.getM_id());
				if (foodMealKeshou_today != null) {// 美食如果当日已经设置
					// 美食删除当日设置
					partnerService.deleteTodayFoodMealKeshous(foodMealKeshou_today.getK_id());
				}
				// 美食添加新的可售设置
				partnerService.addFoodMealKeshous(foodMealKeshou);
			}
		}

		return Msg.success();
	}

	// 删除美食套餐
	@RequestMapping("/delFoodMeal")
	public Msg delFoodMeal(Integer m_id) {
		boolean delResult = partnerService.delFoodMeal(m_id);
		return Msg.judge(delResult);
	}

	// 修改美食套餐
	@RequestMapping("/updFoodMeal")
	public Msg updFoodMeal(FoodMeal foodMeal) {
		boolean updResult = partnerService.updFoodMeal(foodMeal);
		return Msg.judge(updResult);
	}

	// 添加美食图片
	@RequestMapping("/addFoodMealPhoto")
	public Msg addFoodMealPhoto(FoodMealPhoto foodMealPhoto) {
		int insResult = partnerService.addFoodMealPhoto(foodMealPhoto);
		if (insResult > 0) {
			return Msg.success();
		}
		return Msg.fail();
	}

	// 删除美食图片
	@RequestMapping("/delFoodMealPhoto")
	public Msg delFoodMealPhoto(String photo_id) {
		boolean delResult = partnerService.delFoodMealPhoto(photo_id);
		return Msg.judge(delResult);
	}

	/** 娱乐 */
	// 上下架娱乐项目 upordowntype 0 上架 1下架
	@RequestMapping("/upOrDownHappyTheme")
	public Msg upOrDownHappyTheme(int happyThemeid, String upordowntype) {
		boolean updResult = partnerService.upOrDownHappyTheme(happyThemeid, upordowntype);
		return Msg.judge(updResult);
	}

	// 筛选（根据上下架筛选）--p_id商家id upordowntype --0 上架 1下架
	@RequestMapping("/shaixuanUporDownHappyTheme")
	public Msg shaixuanUporDownHappyTheme(String p_id, String upordowntype) {
		List<HappyTheme> happyThemes = partnerService.shaixuanUporDownHappyTheme(p_id, upordowntype);
		return Msg.success().add("happyThemes", happyThemes);
	}

	// 获取娱乐项目详情
	@RequestMapping("/getHappyThemeXQ")
	public Msg getHappyThemeXQ(String t_id) {
		HappyTheme happyTheme = partnerService.getHappyThemeXQ(t_id);
		if (happyTheme != null) {
			return Msg.success().add("happyTheme", happyTheme);
		}
		return Msg.fail();
	}

	// 娱乐项目设置可销售数量
	@RequestMapping("/setupKeshouHappyTheme")
	public Msg setupKeshouHappyTheme(@RequestBody List<HappyThemeKeshou> happyThemeKeshous) {
		if (happyThemeKeshous != null && happyThemeKeshous.size() > 0) {
			for (HappyThemeKeshou happyThemeKeshou : happyThemeKeshous) {
				// 娱乐项目查询当日是否已经设置可售
				HappyThemeKeshou happyThemeKeshou_today = partnerService.getTodayIsSetupHappyTheme(happyThemeKeshou.getDate(), happyThemeKeshou.getT_id());
				if (happyThemeKeshou_today != null) {// 娱乐项目如果当日已经设置
					// 娱乐项目删除当日设置
					partnerService.deleteTodayHappyThemeKeshous(happyThemeKeshou_today.getK_id());
				}
				// 娱乐项目添加新的可售设置
				partnerService.addHappyThemeKeshous(happyThemeKeshou);
			}
		}

		return Msg.success();
	}

	// 删除娱乐项目
	@RequestMapping("/delHappyTheme")
	public Msg delHappyTheme(Integer t_id) {
		boolean delResult = partnerService.delFoodMeal(t_id);
		return Msg.judge(delResult);
	}

	// 修改娱乐项目
	@RequestMapping("/updHappyTheme")
	public Msg updHappyTheme(HappyTheme happyTheme) {
		boolean updResult = partnerService.updHappyTheme(happyTheme);
		return Msg.judge(updResult);
	}

	// 添加娱乐项目图片
	@RequestMapping("/addHappyThemePhoto")
	public Msg addHappyThemePhoto(HappyThemePhoto happyThemePhoto) {
		int insResult = partnerService.addHappyThemePhoto(happyThemePhoto);
		if (insResult > 0) {
			return Msg.success();
		}
		return Msg.fail();
	}

	// 删除娱乐项目图片
	@RequestMapping("/delHappyThemePhoto")
	public Msg delHappyThemePhoto(String photo_id) {
		boolean delResult = partnerService.delHappyThemePhoto(photo_id);
		return Msg.judge(delResult);
	}

}
